#include"sock_init.h"
int read_info_cnf(struct info_data * p)
{
    if(NULL == p)return -1;
    FILE * fp = fopen("info.cnf", "r");
    if(NULL == fp)return -1;
    while(1)
    {
        char buff[128] = {0};
        fgets(buff, 128, fp);
        if(buff[0] == '\0')
        {
         /* printf("file EOF\n"); */
            break;
        }
        if(buff[0] == '#' || buff[0] == '\n')continue;
     /* printf("buff = %s", buff); */
        /* order to remove the '\n' */
        buff[strlen(buff)-1] = '\0';
        if(strncmp(buff, "ipstr=", 6)==0)
        {
            strcpy(p->ipstr, buff+6);
            continue;
        }
        else if(strncmp(buff, "port=", 5)==0)
        {
            p->port = atoi(buff+5);
            continue;
        }
        else if(strncmp(buff, "lismax=", 7)==0)
        {
            p->lismax = atoi(buff+7);
            continue;
        }
        else
        {
            printf("info.cnf error: %s",buff);
        }
    }
    fclose(fp);
    return 0;
}